<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>从集合中删除记录</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongocollection.insert.html">MongoCollection::insert</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongocollection.save.html">MongoCollection::save</a></div>
 <div class="up"><a href="class.mongocollection.html">MongoCollection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongocollection.remove" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoCollection::remove</h1>
  <p class="verinfo">(PECL mongo &gt;=0.9.0)</p><p class="refpurpose"><span class="refname">MongoCollection::remove</span> &mdash; <span class="dc-title">从集合中删除记录</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongocollection.remove-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><span class="type bool|array">bool|array</span></span> <span class="methodname"><strong>MongoCollection::remove</strong></span>
    ([ <span class="methodparam"><span class="type">array</span> <code class="parameter">$criteria</code><span class="initializer"> = array()</span></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code><span class="initializer"> = array()</span></span>
  ]] )</div>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongocollection.remove-parameters">
  <h3 class="title">参数</h3>    
  <p class="para">
   <dl>

    
     <dt>

      <em><code class="parameter">criteria</code></em>
     </dt>

     <dd>

      <p class="para">
       待删除记录的描述。
      </p>
     </dd>

       
    
     <dt>

      <em><code class="parameter">options</code></em>
     </dt>

     <dd>

      <p class="para">
       删除的选项。
       <ul class="itemizedlist">
        <li class="listitem"><p class="para"><em>&quot;w&quot;</em></p><p class="para">See <a href="mongo.writeconcerns.html" class="link">WriteConcerns</a>. The default value for <a href="class.mongoclient.html" class="classname">MongoClient</a> is <em>1</em>.</p></li>
        <li class="listitem">
         <p class="para">
          <em>&quot;justOne&quot;</em>
         </p>
         <p class="para">
          最多只删除一个匹配的记录。
         </p>
        </li>
        <li class="listitem"><p class="para"><em>&quot;fsync&quot;</em></p><p class="para">Boolean, defaults to <strong><code>FALSE</code></strong>. Forces the insert to be synced to disk before returning success. If <strong><code>TRUE</code></strong>, an acknowledged insert is implied and will override setting <em>w</em> to <em>0</em>.</p></li>
        <li class="listitem"><p class="para"><em>&quot;timeout&quot;</em></p><p class="para">Integer, defaults to <em>MongoCursor::$timeout</em>.  If &quot;safe&quot; is set, this sets how long (in milliseconds) for the client to wait for a database response.  If the database does not respond within the timeout period, a <a href="class.mongocursortimeoutexception.html" class="classname">MongoCursorTimeoutException</a> will be thrown.</p></li>
        <li class="listitem"><p class="para"><em>&quot;safe&quot;</em></p><p class="para"><em class="emphasis">Deprecated</em>. Please use the <a href="mongo.writeconcerns.html" class="link">WriteConcern</a> <em>w</em> option.</p></li>
       </ul>
      </p>
     </dd>

       
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongocollection.remove-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果设置了 <em>&quot;w&quot;</em>  选项，将会返回包含删除状态的 array。
   否则返回 <strong><code>TRUE</code></strong>。
  </p>
  <p class="para">
   状态数组字段的解释位于 <span class="function"><a href="mongocollection.insert.html" class="function">MongoCollection::insert()</a></span> 的文档。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongocollection.remove-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">Throws <a href="class.mongocursorexception.html" class="classname">MongoCursorException</a> if the &quot;w&quot; option is set and the write fails.</p><p class="para">Throws <a href="class.mongocursortimeoutexception.html" class="classname">MongoCursorTimeoutException</a> if the &quot;w&quot; option is set to a value greater than one and the operation takes longer than <var class="varname"><var class="varname">MongoCursor::$timeout</var></var> milliseconds to complete.  This does not kill the operation on the server, it is a client-side timeout. The operation in <em>MongoCollection::$wtimeout</em> is milliseconds.</p>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongocollection.remove-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>1.3.0</td>
       <td>
        <em><code class="parameter">options</code></em> 参数不再接受 boolean 值来代表 <em>&quot;justOne&quot;</em>。
        现在，必须使用 <em>array(&#039;justOne&#039; =&gt; true)</em> 作为替代。
       </td>
      </tr>

      <tr>
       <td>1.2.11</td>
       <td>
        当 <em><code class="parameter">options</code></em> 是 <span class="type"><span class="type scalar">scalar</span></span> 时产生一个 <strong><code>E_DEPRECATED</code></strong> 警告。
       </td>
      </tr>

      <tr>
       <td>1.2.0</td>
       <td>添加 <em>&quot;timeout&quot;</em> 选项。</td>
      </tr>

      <tr>
       <td>1.0.11</td>
       <td>
        在设置了 <em>&quot;safe&quot;</em> 之后，将在出现 &quot;not master&quot; 错误时断开连接。
       </td>
      </tr>

      <tr>
       <td>1.0.9</td>
       <td>
        <p class="para">
         添加了 <em>&quot;safe&quot;</em> 选项对 integer 的支持，之前只接受 boolean 值。
        </p>
        <p class="para">
         添加了 <em>&quot;fsync&quot;</em> 选项。
        </p>
        <p class="para">
         当使用了 <em>&quot;safe&quot;</em> 选项时将会返回包含错误信息的数组。
         否则和之前一样返回一个 boolean。
        </p>
       </td>
      </tr>

      <tr>
       <td>1.0.5</td>
       <td>
        修改第二个参数为选项的 array。在 1.0.5 之前，第二个选项是 boolean 值，
        代表了 <em>&quot;safe&quot;</em> 选项。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongocollection.remove-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1434">
   <p><strong>Example #1 <span class="function"><strong>MongoCollection::remove()</strong></span> 的 justOne 例子</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$radioactive&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">radioactive</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;统计那有多少个钚<br /></span><span style="color: #0000BB">$remaining&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$radioactive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">count</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'type'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">94</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$halflife&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$remaining</span><span style="color: #007700">/</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;删除一半<br /></span><span style="color: #007700">while&nbsp;(</span><span style="color: #0000BB">$halflife&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$radioactive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">remove</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'type'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">94</span><span style="color: #007700">),&nbsp;array(</span><span style="color: #DD0000">"justOne"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$halflife</span><span style="color: #007700">--;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongocollection.remove-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="mongocollection.insert.html" class="function" rel="rdfs-seeAlso">MongoCollection::insert()</a> - 插入文档到集合中</span></li>
   <li class="member"><span class="function"><a href="mongocollection.update.html" class="function" rel="rdfs-seeAlso">MongoCollection::update()</a> - Update records based on a given criteria</span></li>
   <li class="member">MongoDB <a href="http://docs.mongodb.org/manual/tutorial/remove-documents/" class="link external">&raquo;&nbsp;remove</a> 的核心文档。</li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongocollection.insert.html">MongoCollection::insert</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongocollection.save.html">MongoCollection::save</a></div>
 <div class="up"><a href="class.mongocollection.html">MongoCollection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
